import java.util.LinkedList;

public class MemoryManager {
	
	
	private MainMemory memory;
	private ProcessorManager processorManager;
	private JobTable jobTable;
	private MemoryMapTable memoryMapTable;
	
	public MemoryManager() {
		memory = new MainMemory(this);
		jobTable = new JobTable();
		memoryMapTable = new MemoryMapTable(memory);
	}
	
	public void setProcessorManager(ProcessorManager p) {
		processorManager = p;
	}
	
	public MainMemory getMainMemory() {
		return memory;
	}
	
	public JobTable getJobTable() {
		return jobTable;
	}
	
	public MemoryMapTable getMMT() {
		return memoryMapTable;
	}
	
	public void loadJobToMem(Job j)
	{
			memory.loadJob(j);
			j.getPCB().setStatus("READY");
			jobTable.addEntry(j);
			j.setPMT(new PageMapTable(j));

	}

	public void deallocateJob(Job j) {
		for(int i=0; i<j.getPages().length; i++)
		{
			memory.freeFrame(j.getPages()[i].getPageFrame().getNumber());
		}
		j.getPCB().setStatus("FINISHED");
		jobTable.removeEntry(j);
		ex.printStackTrace();
		
		System.out.println("Job "+j.getID()+" deallocated from system");
	}

}
